#include <bits/stdc++.h>
#define PR(x) printf(x ? "YES\n" : "NO\n")
#define pr(x) printf(x ? "Yes\n" : "No\n")
#define mk make_pair
#define pb emplace_back
#define fi first
#define se second
#define pii pair<int, int>
#define fore(i, u) for (int i = h[u]; i; i = e[i].nxt)
#define all(x) x.begin(), x.end()
#define int long long

using namespace std;
inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (! isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

const int maxn = 100 + 5;
int n, k, a[maxn];

namespace sub1 {

	const int N = 1 << 15;
	int v[N], c[N], f[N];

	void work() {
		for (int i = 0; i < (1 << n); i ++) {
			bool fl = n / k == __builtin_popcount(i);
			
			int lst = -1, res = 0;
			for (int j = 0; j < n; j ++)
				if ((i >> j) & 1) {
					if (lst != -1) res += a[j] - lst, fl &= a[j] != lst;  
					lst = a[j];
				}
			
			if (fl) c[i] = 1, v[i] = res;
		}

		memset(f, 0x3f, sizeof f), f[0] = 0;
		for (int i = 1; i < (1 << n); i ++)
			for (int j = i; j; j = (j - 1) & i)
				if (c[j]) f[i] = min(f[i], f[i ^ j] + v[j]);
		
		int t = f[(1 << n) - 1];
		if (t > 1e15) cout << -1; else cout << t;
	}
}

signed main() {

	freopen("diyiti.in", "r", stdin);
	freopen("diyiti.out", "w", stdout);
	
	n = read(), k = read();
	for (int i = 0; i < n; i ++) a[i] = read();

	sort(a, a + n);
	if (n <= 15) sub1 :: work(); 

	return 0;
}